﻿  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebTemplate.DAL.Entities;
using WebTemplate.DAL.Repositories;

namespace WebTemplate.Web.News
{
    public partial class news_details : System.Web.UI.Page
    {
        private int? Id
        {
            get
            {
                var idstr = this.Request.QueryString["id"];
                if (string.IsNullOrWhiteSpace(idstr))
                    return null;
                return int.Parse(idstr);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Id.HasValue)
                {
                    NewsRepository repository = new NewsRepository();
                    var news = repository.Select(new NewsSearchCriteria() { Id = this.Id.Value }).First();

                    this.txtTitle.Text = news.Title;
                    this.txtShortDescription.Text = news.ShortDescription;
                    this.photo.ImageUrl = news.ImageUrl;
                    this.txtDescription.Text = news.Description;
                }
            }

            
        }

    }
}